import logging


from redis import StrictRedis


class Config(object):
    # 项目的配置
    DEBUG = True

    SECRET_KEY = "xCMZoOvXK6CYiZ9CqX4WFjyPuveTyjUrf9aHj2kSriWd9diE4ZPbc/TemUF7z21O"

    # 为数据库添加配置
    SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/information"
    # 是否追踪操作，节省资源
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    # 配置参数，以后commit不用写提交
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True
    # Redis的配置
    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = 6379

    # Session保存配置
    SESSION_TYPE = "redis"
    # 开启session签名
    SESSION_USE_SINGER = True
    # 指定 session 保存的redis,　这个是专门存储session的
    SESSION_REDIS = StrictRedis(host=REDIS_HOST,port=REDIS_PORT)
    # 设置是否需要过期
    SESSION_PERMANENT = False
    # 设置过期时间
    PERMANENT_SESSION_LIFETIME = 86400 * 2

    # 设置日志等级
    LOG_LEVEL = logging.DEBUG


class DevelopmentConfig(Config):
    """开发环境下的配置"""
    DEBUG = True


class ProductionConfig(Config):
    """生产环境下的配置"""
    DEBUG = False
    LOG_LEVEL = logging.WARNING


class TestingConfig(Config):
    """单元测试环境下的配置"""
    DEBUG = True
    # 程序出错时，会显示定位到那一行
    TESTING = True


# 定义配置字典
config = {
    "development": DevelopmentConfig,
    "production": ProductionConfig,
    "testing": TestingConfig
}